<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\User;
use App\UsersProfile;


use App\Http\Requests;

class Counselor extends Controller
{
    //咨询师列表
    public function lists(Request $request)
    {

        $data = user::where('status', 1)->where('identity', 1)->get();
        $rst = array();
        $idx = array();
        if($data)
        {
            foreach($data as $k => $v)
            {
                $rst[] = array(
                    'id' => $v->id,
                    'mobile' => $v->mobile,
                    'photo' => $v->photo,
                    'username' => $v->username,
                );
                $idx[] = $v->id;
            }
        }

        if($idx)
        {
            $profile_rst = array();
            $profile_data = UsersProfile::find($idx);
            if($profile_data)
            {
                foreach($profile_data as $k => $v)
                {
                    $profile_rst[$v->user_id] = array(
                        'title_level' => $v->title_level,
                        'education' => $v->education,
                        'graduation_school' => $v->graduation_school,
                        'direciton_tag' => $v->direciton_tag,
                        'introduction' => $v->introduction
                    );
                }

                foreach($rst as $k => $v)
                {
                    $rst[$k] = array_merge($v, $profile_rst[$v['id']]);
                }
            }
        }


        return response(array('code' => '', 'msg' => '', 'rst' => $rst));
    }
}
